<style scoped lang='less'>
    .demo-upload-list {
        display: inline-block;
        width: 60px;
        height: 60px;
        text-align: center;
        line-height: 60px;
        border: 1px solid transparent;
        border-radius: 4px;
        overflow: hidden;
        background: #fff;
        position: relative;
        box-shadow: 0 1px 1px rgba(0, 0, 0, .2);
        margin-right: 4px;
    }

    .demo-upload-list img {
        width: 100%;
        height: 100%;
    }

    .demo-upload-list-cover {
        display: none;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(0, 0, 0, .6);
    }

    .demo-upload-list:hover .demo-upload-list-cover {
        display: block;
    }

    .demo-upload-list-cover i {
        color: #fff;
        font-size: 20px;
        cursor: pointer;
        margin: 0 2px;
    }

    .selected-search {
        box-shadow: 0 1px 6px rgba(0, 0, 0, .2);
        height: 200px;
        width: 260px;
        position: relative;
        border-radius: 4px;
    }

    .selected-search .search-action {
        position: absolute;
        top: 10px;
        left: 10px;
        right: 10px;
    }

    .selected-search .selected-arr {
        position: absolute;
        top: 50px;
        left: 20px;
        right: 20px;
        bottom: 10px;
        overflow: scroll;
    }

    .select-click {
        border: 1px solid #dddee1;
        border-radius: 4px;
        padding: 0 10px;
        margin-bottom: 10px;
    }

    .selected-search .selected-arr .selected-item {
        /*border-bottom: 1px solid #dfdfdf;*/
    }

    .apply-holiday {
        background-image: url('../../assets/image/xujia.png');
        background-size: 55%;
    }

</style>
<template>
    <div class="apply-holiday" style="width: 40%">
        <i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="100">
            <selectSearch :selectBaseInfo="selectBaseInfo" @post-data="getCompentensData"></selectSearch>
            <Form-item label="请假原因" prop="reason">
                <i-input type="textarea" v-model="formValidate.reason" placeholder="请假原因"></i-input>
            </Form-item>
            <Form-item label="请假人姓名" prop="reqpeople">
                <i-input v-model="formValidate.reqpeople" placeholder="请假人姓名" :disabled="isDisabled"></i-input>
            </Form-item>
            <Form-item label="请假人电话" prop="phone">
                <i-input v-model="formValidate.phone" placeholder="请假人电话"></i-input>
            </Form-item>
            <Form-item label="人员类型" prop="reqpeopletype">
                <i-select v-model="formValidate.reqpeopletype" placeholder="请选择适用人员类型">
                    <template v-for="(item,index) in peopleTypeArr">
                        <i-option :value="item.Id">{{item.PeopleTypeTitle}}</i-option>
                    </template>
                </i-select>
            </Form-item>
            <Form-item label="部门">
                <i-input v-model="orgName"
                         placeholder="部门"
                         :disabled="isDisabled"></i-input>
            </Form-item>
            <Form-item label="外出目的地" prop="destination">
                <i-input v-model="formValidate.destination" placeholder="外出目的地"></i-input>
            </Form-item>
            <Form-item label="请假类型" prop="resttype">
                <i-select v-model="formValidate.resttype" placeholder="请选择请假类型">
                    <template v-for="(item,index) in resttypeArr">
                        <i-option :value="item.TypeName">{{item.TypeName}}</i-option>
                    </template>
                </i-select>
            </Form-item>
            <Form-item label="开始时间">
                <Row>
                    <i-col span="11">
                        <Date-picker type="datetime" placeholder="选择开始日期" @on-change="changeStartDate"></Date-picker>
                    </i-col>
                </Row>
            </Form-item>
            <Form-item label="结束时间">
                <Row>
                    <i-col span="11">
                        <Date-picker type="datetime" placeholder="选择结束日期" @on-change="changeEndDate"></Date-picker>
                    </i-col>
                </Row>
            </Form-item>
            <Form-item>
                <i-button @click="handleSubmit('formValidate')" type="primary">提交</i-button>
                <i-button @click="jumpPage('','supplierAllBack')" type="ghost" style="margin-left: 8px">重置</i-button>
            </Form-item>
        </i-form>
        <Modal v-model="isShowModal2" title="选择部门" @on-ok=""
               @on-cancel="isShowModal2 =false">
            <Tree :show-checkbox="showCheckbox" :data="orgData" @on-select-change="orgClickEvent"></Tree>
        </Modal>
    </div>
</template>
<script>

    import apiUtil from '../../assets/utils/api_util';
    import selectSearch from '../../components/selectSearch';

    /*
     * 请假人的人员id id,
     * 请假人姓名 reqpeople,
     * 所在部门 reqpeopleDept,
     * 请假的起始时间 reqstartdate，
     * 请假的结束时间 reqstartdate,
     * 请假理由 reason，
     * 请假类型 resttype
     * */


    export default {
        data() {
            return {
                //组织选择树形
                showCheckbox: false,
                isShowModal2: false,
                orgData: [],
                //部门名称、id
                orgId: '',
                orgName: '',
                //表单数据
                formValidate: {
                    //添加字段
                    reqstartdate: '',
                    reqenddate: '',
                    reason: '',
                    resttype: '',
                    destination: '',
                    reqpeople: '', //请假人
                    reqpeopletype: '', //人员类型
                    phone: '',
                },
                ruleValidate: {},
                userDetailInfo: '',
                //请假类型列表
                resttypeArr: [],
                //门区列表
                geteListArr: [],
                //选择部门
                selectBaseInfo: {
                    "title": '选择人员',
                    "placeholder": '请输入姓名',
                    "postUrl": apiUtil.urls.userList,
                    'postType': 'user',
                },
                reqpeopleDept: '',
                //请假人选择操作
                principalId: '',
                principalArr: [],
                personalName: '请选择请假人',
                selectPeopelIsShow: false,
                papertypeArr: [],
                //人员类型
                peopleTypeArr: [],
                //是否禁用
                isDisabled: true,
                //操作人所在部门
                creatorOrg: {},
            }
        },
        mounted: function () {
            this.getRestTypeData();
            this.getGateList();
            this.getPeopleTypeData();
            this.getCreatorOrg();
        },

        components: {
            selectSearch
        },
        methods: {
            jumpPage: function (id, url) {
                //跳转
                let route = '';
                if (id.length > 0) {
                    route = {
                        path: url,
                        query: {
                            id: id
                        },
                    };
                } else {
                    route = {
                        path: url,
                    };
                }

                this.$router.push(route);
            },
            handleSubmit(name) {

                let that = this;
                let model = this.$refs[name].model;
                console.log('jin')
                that.addData(model);
                // this.$refs[name].validate((valid) => {
                //
                //     console.log('zher')
                //
                // })
            },
            //获取适用人员类型
            getPeopleTypeData: function () {
                let that = this;

                let para = {};
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.GetPeopleTypes, params, function (res) {
                    that.$Loading.finish();
                    that.peopleTypeArr = res.Msg;
                });
            },
            changeStartDate: function (date) {
                console.log(date);
                this.formValidate.reqstartdate = date;
            },
            changeEndDate: function (date) {
                console.log(date);
                this.formValidate.reqenddate = date;
            },
            //获取选择搜索组件传来结果数据
            getCompentensData: function (value) {
                this.reqpeopleDept = value;
                this.getDetail(value.resultId);
                this.isDisabled = true;
            },
            //详情
            getDetail: function (id) {
                let that = this;
                that.$Loading.start();

                let para = {
                    id: id,
                };

                apiUtil.get(that, apiUtil.urls.userClientDetail, para, function (res) {
                    that.userDetailInfo = res.Msg;
                    that.orgName = res.Msg.OrgName;
                    that.orgId = res.Msg.Orgid;
                    that.formValidate.phone = res.Msg.Phone;
                    that.formValidate.reqpeopletype = res.Msg.reqpeopletype;
                    that.formValidate.reqpeople = res.Msg.Personalname;
                    that.formValidate.reqpeopletype = res.Msg.Peopletype;
                });
            },
            //获取请假类型
            getRestTypeData: function () {
                let that = this;

                let para = {};
                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.GetRestTypes, para, function (res) {
                    that.$Loading.finish();
                    that.resttypeArr = res.Msg;
                });

            },

            //获取门区信息
            getGateList() {
                let that = this;

                let para = {};
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.GateServerList, para, function (res) {
                    that.$Loading.finish();
                    that.geteListArr = res.Msg;
                });

            },
            //获取请假人列表
            getPeopelData() {
                let that = this;

                let para = {
                    curPage: 1,
                    pageSize: '',
                };
                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.userList, para, function (res) {
                    that.$Loading.finish();

                    that.selectPeopelIsShow = true;
                    that.principalArr = res.Msg.Arrays;
                });
            },
            choosePeople: function (id, name) {
                this.principalId = id;
                this.personalName = name;
                this.selectPeopelIsShow = false;
                this.searchOrg();
            },
            //部门
            searchOrg() {
                let that = this;

                let para = {
                    peopleId: that.principalId,
                };
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.PeopleOrgList, para, function (res) {
                    that.$Loading.finish();
                    that.papertypeArr.push(res.Msg);
                });

            },
            //选择门区
            checkChangeGate: function (data) {
                console.log('多选值:', data);
                let arr = Array.from(data);
                // this.formValidate.gateInfos =arr;
                console.log('checkChangeGate:', arr)

            },
            //获取操作人所在部门
            getCreatorOrg: function () {
                let that = this;
                that.$Loading.start();

                let para = {
                    id: sessionStorage.getItem('userId'),
                };

                apiUtil.get(that, apiUtil.urls.userClientDetail, para, function (res) {

                    that.creatorOrg.id = res.Msg.Orgid;
                    that.creatorOrg.title = res.Msg.OrgName;
                    that.getCreatorOrgData(res.Msg.Orgid);
                });
            },
            //选择部门
            orgClickEvent: function (data) {
                this.orgName = data[0].title;
                this.orgId = data[0].id;
            },
            //获取操作人部门树
            getCreatorOrgData: function (id) {
                let that = this;
                that.$Loading.start();

                let para = {
                    parentId: id,
                };

                apiUtil.get(that, apiUtil.urls.GetDeptList, para, function (res) {
                    that.$Loading.finish();

                    that.orgData = [
                        {
                            id: that.creatorOrg.id,
                            title: that.creatorOrg.title,
                            children: [],
                            expand: true
                        }
                    ];
                    that.orgData[0].children = res.Msg
                    if (res.Msg.length <= 0) {
                        that.orgName = '暂无部门';
                        that.orgId = ''
                    }
                });
            },
            //添加
            addData: function (model) {
                let that = this;

                if (this.reqpeopleDept.resultId && this.reqpeopleDept.resultId.length > 0) {
                    model.reqpersonid = this.reqpeopleDept.resultId;
                }
                else {
                    model.reqpersonid = '';
                }


                model.reqpeopleDept = this.orgName;
                model.reqOrgId = this.orgId;
                model.Isgoon = true;
                model.GoonrequestId = that.$route.query.id;
                // model.creatorpeopleid = '03508730-6f42-438d-b9e7-2465a9653519';
                model.creatorpeopleid = sessionStorage.getItem('userId');
                // model.allowareasection = JSON.stringify(model.allowareasection);

                let params = that.$qs.stringify(model);
                this.$Loading.start();
                console.log('发送数据:', model)

                apiUtil.post(that, apiUtil.urls.CreateRest, params, function (res) {
                    that.$Loading.finish();
                    that.$Message.success('申请成功 ');

                });
            },

            uploadList() {
                let that = this;
                this.imageList = that.$refs.upload ? that.$refs.upload.fileList : [];
                console.log('this.imageList:', this.imageList);
            },

        }
    }
</script>
